package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.web.admin.service.FileService;
import com.minio.template.MinioTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class FileServiceImpl implements FileService {


    @Autowired
    private MinioTemplate minioTemplate;

    @Override
    public String upLoadFile(MultipartFile file) throws Exception {
        //自定义不重复上传文件名
        String date = new SimpleDateFormat("yyyyMMDD").format(new Date());
        String objectName = date+"_"+file.getOriginalFilename();

        //上传蹄片
        minioTemplate.uploadObject(objectName,file.getInputStream(),file.getSize(),file.getContentType());
        //返回图片查看路劲
        return minioTemplate.getObjectUrl(objectName);
    }
}
